<?php
namespace App\Services;

use App\Models\Merchant;
use App\Models\Order;

class OrderService
{
    public function __construct()
    {

    }

    public function create($info, $channelId)
    {
        // 获取商户信息
        $merchant = Merchant::getMercantByClientId($info['client_id']);

        // 根据当前选择随机
        $order = Order::create([
            'merchant_id'    => $merchant->id,
            'user_id'        => $merchant->user->id,
            'channel_id'     => $channelId,
            'status'         => Order::STATUS_UNPAID,
            'from_url'       => $info['from_url'] ?? '',
            'title'          => $info['title'],
            'trade_no'       => order_no(),
            'out_trade_no'   => $info['out_trade_no'],
            'total_amount'   => $info['total_amount'],
            'gateway'        => $info['gateway'],
            'client_ip'      => ip2long(request()->ip()),
            'notify_url'     => $info['notify_url'],
            'return_url'     => $info['return_url'],
        ]);
        return $order;
    }
}
